package com.to.aboomy.bannersample.pagetransformer;

import com.to.aboomy.banner.BannerViewPager;
import ohos.agp.components.Component;

/**
 * @author xujianhong
 * @since 2021-08-06
 */
public class AlphaPageTransformer implements BannerViewPager.PageTransformer {
    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {
        switch (pageType) {
            case PREVIOUS:
                if (offsetPixels < 0) {
                    page.setAlpha(Math.max(Math.abs(offset),0.5F));
                } else {
                    page.setAlpha(1F);
                }
                break;
            case CURRENT:
                if(offsetPixels >= 0){
                    page.setAlpha(Math.max(1-offset,0.5F));
                }else{
                    page.setAlpha(1-Math.abs(offset));
                }
                break;
            case NEXT:
                if(offsetPixels > 0){
                    page.setAlpha(Math.max(offset,0.5F));
                }else{
                    page.setAlpha(Math.max(1+offset,0.5F));
                }
                break;
            case OTHER:
                page.setAlpha(1F);
                break;
        }
    }
}
